//
//  TFLViewController.m
//  BMBlueMoonSFA
//
//  Created by mac on 16/6/5.
//  Copyright © 2016年 www.tang. All rights reserved.
//

#import "TFLViewController.h"
#import "Masonry.h"
#import "TFLPushViewController.h"
#import "TFLModalViewController.h"
#import "BMMainTabBarController.h"
#import "AFNetworking.h"
#import "BMUserLoginTool.h"
@interface TFLViewController ()
@property(nonatomic, weak)UIButton *tockenBtn;
@end

@implementation TFLViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor yellowColor];
    
    NSArray *array = @[
                       @"唐飞龙",
                       @"棠梨"
                       
                       ];
    
    NSDictionary *dic = @{@"test":array,
                          
                          @"test2" :@"证证"
                          };
    
    NSLog(@"%@===",dic);
    
    //添加三个基本按钮
    [self setUI];
    
}

-(void)setUI{

    
    //创建三个按钮
    //1.添加直接modal出来的控制器，带底部tabbar
    UIButton *btn1 =[UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 addTarget:self action:@selector(btnClick1:) forControlEvents:UIControlEventTouchUpInside];
    btn1.backgroundColor = [UIColor redColor];
    [self.view addSubview:btn1];
    //2.push进控制器，不带底部tabbar
    UIButton *btn2 =[UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 addTarget:self action:@selector(btnClick2:) forControlEvents:UIControlEventTouchUpInside];
    btn2.backgroundColor = [UIColor blueColor];
    [self.view addSubview:btn2];
    //3.
    UIButton *btn3 =[UIButton buttonWithType:UIButtonTypeCustom];
    [btn3 setTitle:@"获取tocken" forState:UIControlStateNormal];
    [btn3 addTarget:self action:@selector(btnClick3:) forControlEvents:UIControlEventTouchUpInside];
    btn3.backgroundColor = [UIColor greenColor];
    self.tockenBtn = btn3;
    [self.view addSubview:btn3];

    

    //布局
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.width.height.mas_equalTo(100);
        
        make.top.equalTo(@100);
        
        make.left.equalTo(@50);
        
    }];
    
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.width.height.mas_equalTo(100);

        make.top.equalTo(btn1.mas_bottom).offset(50);
        
        make.left.equalTo(@50);

        
    }];
    
    [btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.width.height.mas_equalTo(100);
        
        make.top.equalTo(btn2.mas_bottom).offset(50);
        
        make.left.equalTo(@50);
        
        
    }];

}

-(void)btnClick1:(UIButton *)btn{


    NSLog(@"======");
    TFLPushViewController *pushVC = [[TFLPushViewController alloc] init];
    
    [self.navigationController pushViewController:pushVC animated:YES];
}

-(void)btnClick2:(UIButton *)btn{


    NSLog(@"-----");
    
    BMMainTabBarController *mainTabBarVC = [[BMMainTabBarController alloc] init];
    
    [self.navigationController presentViewController:mainTabBarVC animated:YES completion:nil];

}

-(void)btnClick3:(UIButton *)btn{
    
    
    //1.拼接参数
    BMUserLoginParam *loginParam = [BMUserLoginParam param];
    loginParam.account = @"804739";
    loginParam.password = @"ANejIRrmFmo=";
    
    //2.访问网络
    [BMUserLoginTool userLoginWithParam:loginParam success:^(BMUserLoginResult *result) {
        
        NSLog(@"加载成功==%@",result);
        
    } failure:^(NSError *error) {
        
        NSLog(@"%@====",error);
        
    }];
}

-(void)testNetWork{

    //发送登入请求
    NSString *url = @"http://angelapi.bluemoon.com.cn:8882/bluemoon-control/user/ssoLogin?appType=moonAngel&client=ios&cuid=92C7958C-2046-4B32-9D8A-F02F82EE8B04&format=json&hig=0&lat=999&lng=999&sign=e97c93e8db83ade60c16d5a4a3442f82&time=1465137483&version=4.0.0";
    
    // 1.获得请求管理者
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    
    NSMutableSet *newSet = [NSMutableSet set];
    newSet.set = mgr.responseSerializer.acceptableContentTypes;
    [newSet addObject:@"text/html"];
    mgr.responseSerializer.acceptableContentTypes = newSet;
    
    mgr.requestSerializer = [AFJSONRequestSerializer serializer];
    [mgr.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    
    NSDictionary *params = @{
                             @"account" : @"80473932",
                             @"password" : @"ANejIRrmFmo="
                             };
    // 2.发送POST请求
    [mgr POST:url parameters:params
      success:^(AFHTTPRequestOperation *operation, id responseObj) {
          //成功
          NSLog(@"%@======",responseObj);
          NSDictionary *dic = responseObj;
          [self.tockenBtn setTitle:dic[@"token"] forState:UIControlStateNormal];
          
      } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
          
          //失败
          NSLog(@"%@=======",error);
          
      }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
